import 'package:flutter/material.dart';

import '../../enums/file_filter_enum.dart';
import 'radio_option.dart';

class FilterGroup extends StatefulWidget {
  final FileFilterEnum currentFilter;
  final ValueChanged<FileFilterEnum?>? onChanged;
  final bool isVertical;
  const FilterGroup(
      {super.key,
      this.currentFilter = FileFilterEnum.book,
      this.isVertical = true,
      this.onChanged});
  @override
  State<FilterGroup> createState() => _FilterGroupState();
}

class _FilterGroupState extends State<FilterGroup> {
  FileFilterEnum _currentFilter = FileFilterEnum.book;

  @override
  void initState() {
    super.initState();
    _currentFilter = widget.currentFilter;
  }

  @override
  Widget build(BuildContext context) {
    const SizedBox vspacer = SizedBox(
      height: 10,
    );
    const SizedBox hspacer = SizedBox(
      width: 10,
    );
    return widget.isVertical
        ? Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              RadioOption(
                  value: FileFilterEnum.book,
                  groupValue: _currentFilter,
                  text: FileFilterEnum.book.title,
                  onChanged: (FileFilterEnum? val) {
                    setState(() {
                      _currentFilter = val!;
                    });
                    widget.onChanged?.call(val);
                  }),
              vspacer,
              RadioOption(
                  value: FileFilterEnum.video,
                  groupValue: _currentFilter,
                  text: FileFilterEnum.video.title,
                  onChanged: (FileFilterEnum? val) {
                    setState(() {
                      _currentFilter = val!;
                    });
                    widget.onChanged?.call(val);
                  }),
              vspacer,
              RadioOption(
                  value: FileFilterEnum.videoAndBook,
                  groupValue: _currentFilter,
                  text: FileFilterEnum.videoAndBook.title,
                  onChanged: (FileFilterEnum? val) {
                    setState(() {
                      _currentFilter = val!;
                    });
                    widget.onChanged?.call(val);
                  })
            ],
          )
        : Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              RadioOption(
                  value: FileFilterEnum.book,
                  groupValue: _currentFilter,
                  text: FileFilterEnum.book.title,
                  onChanged: (FileFilterEnum? val) {
                    setState(() {
                      _currentFilter = val!;
                    });
                    widget.onChanged?.call(val);
                  }),
              hspacer,
              RadioOption(
                  value: FileFilterEnum.video,
                  groupValue: _currentFilter,
                  text: FileFilterEnum.video.title,
                  onChanged: (FileFilterEnum? val) {
                    setState(() {
                      _currentFilter = val!;
                    });
                    widget.onChanged?.call(val);
                  }),
              hspacer,
              RadioOption(
                  value: FileFilterEnum.videoAndBook,
                  groupValue: _currentFilter,
                  text: FileFilterEnum.videoAndBook.title,
                  onChanged: (FileFilterEnum? val) {
                    setState(() {
                      _currentFilter = val!;
                    });
                    widget.onChanged?.call(val);
                  })
            ],
          );
  }
}
